package com.neu.yth.nepBackend.role.controller;

import com.neu.yth.nepBackend.entity.Role;
import com.neu.yth.nepBackend.role.service.IRoleService;
import com.neu.yth.nepBackend.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色表格 前端控制器
 * </p>
 *
 * @author YTH
 * @since 2024-05-31
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    IRoleService roleService;

    /**
     * 查询所有角色
     *
     * @return
     */
    @GetMapping("select/all")
    public Result selectAll() {
        return roleService.selectAll();
    }

    /**
     * 根据id查询角色
     *
     * @param roleId
     * @return
     */
    @GetMapping("select/{roleId}")
    public Result selectById(@PathVariable Integer roleId) {
        return roleService.selectById(roleId);
    }

    /**
     * 添加角色
     *
     * @param role
     * @return
     */
    @PostMapping("insert")
    public Result insert(@RequestBody Role role) {
        return roleService.insert(role);
    }


    /**
     * 更新角色
     *
     * @param role
     * @return
     */
    @PutMapping("update")
    public Result update(@RequestBody Role role) {
        return roleService.updateRoleById(role);
    }

    @DeleteMapping("delete")
    public Result delete(@Param("roleId") Integer roleId) {
        return roleService.deleteById(roleId);
    }

}
